<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">

</div>
<script>
    new Vue({
        el: "#app",
        data: {},
    })
    //箭头函数不会改变原有的this的指向
    let user = {
        username: "小哈",
        app: function () {
            console.log(this.username, 'user')
        }
    }
    user.app()
    let student = {
        username: "小小",
        app: function () {
            setTimeout(function () {
                //此时的this的指向发生改变
                console.log(this.username)
            })
        }
    }
    student.app() //此时显示this未定义

    let emp = {
        username: "夏普",
        app: function () {
            //使用箭头函数   不会影响this的指向
            setTimeout(() => {
                console.log(this.username)
            })
        }
    }
    emp.app()

</script>
</body>
</html>